package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.common.anno.Logs;
import com.qk.dto.customer.CustomerDTO;
import com.qk.dto.customer.CustomerPageDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 *
 * @author blusr
 * @version 1.0
 * @date 2025/10/16 10:15
 */
@Slf4j
@RestController
@RequestMapping("/customers")
@SuppressWarnings("all")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @GetMapping
    public Result getCustomerPage(CustomerPageDTO dto) {
        log.info("分页查询, dto: {}", dto);
        return Result.success(customerService.getCustomerPage(dto));
    }

    @Logs("添加客户")
    @PostMapping
    public Result addCustomer(@RequestBody CustomerDTO dto) {
        log.info("添加客户, dto: {}", dto);
        customerService.addCustomer(dto);
        return Result.success();
    }

    @Logs("根据ID查询客户详情")
    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Integer id) {
        log.info("根据ID查询客户, id: {}", id);
        return Result.success(customerService.getById(id));
    }

    @Logs("更新客户")
    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer) {
        log.info("更新客户, customer: {}", customer);
        customerService.updateCustomerById(customer);
        return Result.success();
    }
}
